<?php
/* @var $form CActiveForm */
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
echo '<h3>' . $model->name . '</h3>';
if ($images != null) {
    if (Yii::app()->user->id == $model->userCreated->id) {
        echo CHtml::link('Sửa', array('collection/edit', 'id' => $model->id)) . '<br>';
        echo CHtml::link('Xóa Collection', array('collection/delete', 'id' => $model->id)) . '<br>';
    }
    $checkLike = CollectionLike::model()->find("collection_id = :collection_id and user_id =:user_id", array(
        ':collection_id' => $model->id,
        ':user_id' => Yii::app()->user->id
    ));
    if ($checkLike) {
        ?>
        <a href="#" class="like_link"
           onclick="return like(<?php echo $model->id; ?>);">Bỏ thích</a><br>
       <?php } else {
           ?>
        <a href="#" class="like_link"
           onclick="return like(<?php echo $model->id; ?>);">Thích</a><br>
           <?php
       }
       foreach ($images as $image) {
           if (Yii::app()->user->id == $model->userCreated->id) {
               echo '<br>' . CHtml::link('Xóa ảnh', array('collection/removeimage', 'image_id' => $image->image_id, 'collection_id' => $image->collection_id)) . '<br>';
           }
           echo $image->image->title . '<br>';
           echo '<img width="200px" src="' . Yii::app()->baseUrl . '/upload/user/' . $image->image->userCreated->id . '/images/' . $image->image->img_url . '" /><br>';
       }
   } else {
       echo 'Collection is empty !';
   }
   if ($allComment != null && sizeof($allComment) > 0) {
       echo '<h2>Bình luận</h2>';
       foreach ($allComment as $cm) {
           echo '<b>' . $cm->user->fullname . '</b><br>';
           echo 'Lúc : ' . Format::timeAgo($cm->comment_at, 'Y-m-d H:i:s') . '<br>';
           echo CHtml::encode($cm->content) . '<br><hr>';
       }
   } else {
       echo 'Chưa có bình luận nào.';
   }
   ?>
<script type="text/javascript">
               function like(id) {
                   $.ajax({
                       url: "<?php echo Yii::app()->createUrl('collection/like') . '?id='; ?>" + id,
                       type: 'GET',
                       success: function(data) {
                           var json = eval('(' + data + ')');
                           $("a.like_link").text(json['meg']);
//                $("p.like_cnt_" + id).text(json['like_cnt']);
                       }
                   });
                   return false;
               }
</script>
<h1>Bình luận</h1>
<div class="form">
    <?php
    $form = $this->beginWidget('CActiveForm', array(
        'id' => 'comment-form',
        'action' => array(
            'collection/comment/' . $model->id
        ),
        'enableClientValidation' => true,
        'clientOptions' => array(
            'validateOnSubmit' => true
        )
    ));
    ?>
    <p class="note">
        Fields with <span class="required">*</span> are required.
    </p>
    <div class="row">
        <?php echo $form->labelEx($comment, 'content'); ?>
        <?php echo $form->textArea($comment, 'content'); ?>
        <?php echo $form->error($comment, 'content'); ?>
    </div>
    <div class="row buttons">
        <?php echo CHtml::submitButton('Đăng'); ?>
    </div>
    <?php $this->endWidget(); ?>
</div>